<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('考勤列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>考勤时间：</label>
                                <input type="text" class="time-input" id="attendMonth" data-type="month" name="attendMonth"/>
                            </li>
                            <li>
                                <label>考勤状态：</label>
                                <select name="attendStatus">
                                    <option value="">所有</option>
                                    <option value="0">未提交</option>
                                    <option value="1">已提交</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="record:attend:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="edit()" shiro:hasPermission="record:attend:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="remove()" shiro:hasPermission="record:attend:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-primary multiple disabled" onclick="submit()" shiro:hasPermission="record:attend:submit">
                    <i class="fa fa-plus"></i> 提交
                </a>
                <a class="btn btn-danger multiple disabled" onclick="recall()" shiro:hasPermission="record:attend:recall">
                    <i class="fa fa-remove"></i> 撤回
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "record/attend";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                modalName: "考勤",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'attendId',
                    title: '考勤id',
                    visible: false
                },
                {
                    field: 'attendMonth',
                    title: '考勤时间',
                    formatter: function (value, row, index){
                        return '<a href="javascript:void(0)" onclick="content(\'' + row.attendId + '\')">' + value + '</a>';
                    }
                },
                {
                    field: 'deptName',
                    title: '考勤科室'
                },
                {
                    field: 'attendUser',
                    title: '考勤人员'
                },
                {
                    field: 'deptUser',
                    title: '科室负责人'
                },
                {
                    field: 'attendStatus',
                    title: '考勤状态',
                    formatter: function (value, row, index) {
                        if(value == '0') {
                            return '<span class="label label-default">未提交</span>';
                        }else if(value == '1') {
                            return '<span class="label label-info">已提交</span>';
                        }
                    }
                },
                {
                    field: 'remark',
                    title: '备注'
                }]
            };
            $.table.init(options);
        });

        /**
         * 招聘计划
         * @param attendId
         */
        function content(attendId){
            var url = ctx + 'record/attend/content/' + attendId;
            $.modal.openTab("考勤内容", url);
        }

        /**
         * 修改
         */
        function edit() {
            var rows = $.table.selectFirstColumns();
            var attendStatus = $.table.selectColumns('attendStatus');
            if(attendStatus != '0'){
                $.modal.alertWarning("请选择未提交的考勤记录进行修改");
                return;
            }
            $.operate.edit(rows);
        }

        /**
         * 删除
         */
        function remove() {
            var attendStatus = $.table.selectColumns('attendStatus');
            if(attendStatus == '0'){
                $.operate.removeAll();
            }else{
                $.modal.alertWarning("请选择未提交的考勤记录进行删除");
                return;
            }
        }

        /**
         * 提交
         */
        function submit(){
            var rows = $.table.selectFirstColumns();
            var attendStatus = $.table.selectColumns('attendStatus');
            if(attendStatus == '0'){
                $.modal.confirm("确定要提交选中的" + rows.length + "条考勤记录吗?", function() {
                    var data = { "attendIds": rows.join() };
                    $.operate.submit(prefix + "/submit", "post", "json", data);
                });
            }else{
                $.modal.alertWarning("请选择未提交的考勤记录进行提交");
                return;
            }
        }

        /**
         * 撤回
         */
        function recall(){
            var rows = $.table.selectFirstColumns();
            var attendStatus = $.table.selectColumns('attendStatus');
            if(attendStatus == '1'){
                $.modal.confirm("确定要撤回选中的" + rows.length + "条考勤记录吗?", function() {
                    var data = { "attendIds": rows.join() };
                    $.operate.submit(prefix + "/recall", "post", "json", data);
                });
            }else{
                $.modal.alertWarning("请选择已提交的考勤记录进行撤回");
                return;
            }
        }
    </script>
</body>
</html>